package com.etc.controller;

import com.etc.entity.Watercup;
import com.etc.service.IWaterCupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author
 * @Description
 * @Date 2021/1/4  17:02
 **/
@RestController
@RequestMapping("/waterCup")
public class WaterCupController {
    @Autowired
    private IWaterCupService IwaterCupService;

    @GetMapping("/findAll")
    public List<Watercup> getWaterCup() {
        List<Watercup> all = IwaterCupService.findAll();
        return all;
    }

    @GetMapping("/getWBI/{wId}")
    public Watercup getWaterCupById(@PathVariable(value = "wId") int wId) {
//            @RequestParam(value = "wId",defaultValue = "1") int wId){
        Watercup byId = IwaterCupService.getById(wId);
        return byId;
    }

    @GetMapping("/getWBN/{wName}")
    public List<Watercup> getWaterCupByName(@PathVariable(value = "wName") String wName) {
        List<Watercup> waterCupByName = IwaterCupService.findWaterCupByName(wName);
        return waterCupByName;
    }
//@PutMapping("/add")
    @GetMapping("/add")
    public Integer addWaterCup(Watercup watercup) {

        Integer add = IwaterCupService.add(watercup);
        return add;
    }
//@DeleteMapping("/delete")
    @GetMapping("/delete")
    public Integer deleteById(Integer wId) {
        Integer integer = IwaterCupService.deleteById(wId);
        return integer;
    }
//    @PutMapping("/update")
@GetMapping("/update")
   public Integer update(Watercup watercup){
    Integer update = IwaterCupService.update(watercup);
    return  update;
}

}